/*
 * @Author: HuRrongChao 1556810922@qq.com
 * @Date: 2024-10-08 17:02:40
 * @LastEditors: HuRrongChao
 * @LastEditTime: 2025-04-22 19:59:58
 */
import axios from '@/axios.js'
const api = {
  toRegister(data) {
    return axios.post('/register', data)
  },
  toLogin(val) {
    return axios.post('/login', val)
  },
  isLogin() {
    return axios.get('/isLogin')
  },
  getRefreshToken(val) {
    return axios.post('/refreshToken', val)
  },
  getVideoList() {
    return axios.get('/getVideoList')
  },
  searchVideos(data) {
    return axios.post('/searchVideos', data)
  },
  getUserVideos(data) {
    return axios.post('/getUserVideos', data)
  },
  getComment(id) {
    return axios.get(`/getComment/${id}`)
  },
  addComment(data) {
    return axios.post('/addComment', data)
  },
  recordHistory(data) { // 记录观看历史
    return axios.post('/recordHistory', data)
  },
  shareVideo(data) { // 分享
    return axios.post('/shareVideo', data)
  },
  toggleLike(data) { // 点赞
    return axios.post('/toggleLike', data)
  },
  toggleCollection(data) { // 收藏
    return axios.post('/toggleCollection', data)
  },
  getLikeStatus(data) { // 获取点赞状态
    return axios.post('/getLikeStatus', data)
  },
  getCollectionStatus(data) { // 获取收藏状态
    return axios.post('/getCollectionStatus', data)
  },
  fileHandshake(fileInfo) {
    return axios.post(`/file/upload/handshake`, fileInfo)
  },
  uploadFilePiece(formData) {
    return axios.post(`/file/upload`, formData)
  },
  uploadFile(file, params = {}) {
    const formData = new FormData();
    formData.append('file', file);
    
    // 将额外的参数添加到 formData 中
    Object.keys(params).forEach(key => {
      formData.append(key, params[key]);
    });

    return axios.post('/uploadFile', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      }
    });
  },
  // 弹幕
  addDanmaku(data) {
    return axios.post('/addDanmaku', data)
  },
  // 聊天室部分
  getFriends() { //好友列表
    return axios.get(`/friends`)
  },
  getMessages(params) { //聊天记录
    return axios.get(`/messages`, { params })
  },
  sendMessage(data) { //发送消息
    return axios.post(`/sendMessage`, data)
  },
  deleteFriendship(data) { //删除好友
    return axios.post(`/deleteFriendship`, data)
  },
  followUser(data) { //关注用户
    return axios.post(`/followUser`, data)
  },
  searchUsers(data) { //搜索用户
    return axios.post(`/searchUsers`, data)
  },
  getForumPosts(data) { //获取论坛帖子
    return axios.post(`/getForumPosts`, data)
  },
  createPost(data) { //创建帖子
    return axios.post(`/createPost`, data)
  },
  getPostComments(data) { //获取帖子评论
    return axios.post(`/getPostComments`, data)
  },
  createComment(data) { //创建评论
    return axios.post(`/createComment`, data)
  },
  togglePostLike(data) { //点赞帖子
    return axios.post(`/togglePostLike`, data)
  },
  // 表白墙部分
  getConfessionBarrages() {
    return axios.get(`/getConfessionBarrages`)
  },
  sendConfessionBarrage(data) {
    return axios.post(`/sendConfessionBarrage`, data)
  }
}

export default api